<?php

/**
 * VIEWER [Obj]
 *
 * Params:
 * 			tmpl_header		- name of header tmplate in {plugin}/_tmpl dir
 * 			tmpl_name 		- name of tmplate in {plugin}/_tmpl dir
 *  		tmpl_footer		- name of footer tmplate in {plugin}/_tmpl dir
 * 
 * VIEWER
 * Params:
 * 			table			- table
 * 			tmpl_header		- name of header tmplate in {plugin}/_tmpl dir
 * 			tmpl_name 		- name of tmplate in {plugin}/_tmpl dir
 *  		tmpl_footer		- name of footer tmplate in {plugin}/_tmpl dir
 * 			check_fields 	- array('field'=>array('value', 'comparators')) - list of fields to check
 * 			sort_by			- sort field
 * 			join			- array(array('t1.f', 't2.f')) - list of fields to join
 * 
 */
  
class zdViewerComponents extends sfComponents
{
  public function executeViewObj($request)
  {
    $c = new Criteria();

    // is published
        $c->add(ObjPeer::IS_PUBLISHED, 1);
        $c->add(ObjPeer::DT_PUBLISHED, date("Y-m-d"), Criteria::LESS_THAN);

    // id
        $c->add(ObjPeer::ID, $this->getRequestParameter('id',1));

    // select
        $this->v = ObjPeer::doSelectOne($c);
        if ($this->v)
        {
        	if (date("Y-m-d", $this->v->getViewAt(null))<date("Y-m-d"))
        		$this->v->setViewCnt(0);        	
        	$this->v->setViewCnt($this->v->getViewCnt()+1);
        	$this->v->setViewAt(date("Y-m-d"));
        	$this->v->save();
        }        
  }

  public function executeView($request)
  {
  	
  	  ////Устанавливаем заголовки		
  	
  	 if(isset($this->seo_title))
  	 {
  	 	$seo_title = $this->seo_title;
  	 }
  	 else {
  	 	$seo_title = 'Заголовок не задан';
  	 }
    	 if(isset($this->seo_keyword))
  	 {
  	 	$seo_keyword = $this->seo_keyword;
  	 }
    	 else {
  	 	$seo_keyword = 'Заголовок не задан';
  	 }
  	 
  	 
    	 if(isset($this->seo_description))
  	 {
  	 	$seo_description = $this->seo_description;
  	 }
    	 else {
  	 	$seo_description = 'Заголовок не задан';
  	 }
  	   
		  	$this->getResponse()->addMeta('title', $seo_title);
		    $this->getResponse()->addMeta('keywords', $seo_keyword);
		    $this->getResponse()->addMeta('description', $seo_description);
	   ////   
  	
      $c = new Criteria();
     $c->add(MaterialPeer::ID,$this->id);
     
    
     
     /*
	// join
	    if(is_array($this->getVar('join', '')))
	    {
	        foreach ($this->join as $v)
	        {
				$c->addJoin($v[0], $v[1]);
	        }
	    }
	    
    // check fields
	    if(is_array($this->getVar('check_fields', '')))
	    {
	        foreach ($this->check_fields as $k=>$v)
	        {
	            $c->add($k, $v[0], $v[1]);
	        }
	    }
	    
	// order
		if ($this->getVar('sort_by', '') != '')
			$c->addAscendingOrderByColumn($this->sort_by);
		*/	
    // select
        $pager = new sfPropelPager('Material', 1);
        $pager->setCriteria($c);
        $pager->setPage(1);
        $pager->setPeerMethod('doSelectOne');
        $pager->init(); 

     // get result
	    $this->v = $pager->getResults();
	    
	     ///Добавляем просмотр
	  $this->v->setSee($this->v->getSee()+1);   
      $this->v->mysave();
        
	    
  }
}
?>